% ========================================
% Page layout
\RequirePackage[left=1.45in,right=1.45in,top=1in,bottom=1in]{geometry}

% fancyhdr
\fancypagestyle{bodypage}{%
\fancyhf{}% clear all six fields
\fancyhead[RE,LO]{\small \textit{Introduction to Proofs}, Hef{}feron, version~\version}
\fancyhead[LE,RO]{\small page \thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0pt}
}

\pagestyle{prefacepage}
\AtBeginDocument{\thispagestyle{firstpage}}

% ========================================
% Answers
% This has to go in this .sty because it opens and empties answers.tex, 
% which would be bad if you ran pdflatex answers.
\usepackage{answers}
\Newassociation{ans}{answer}{answers}
\Opensolutionfile{answers}[answersbody]

% \begin{Filesave}{answers}
% \documentclass{ibl}
% \begin{document}
% \begin{answerlist}  
% \end{Filesave}

\AtEndDocument{%
\Closesolutionfile{answers}}


% ========================================
% Title-ing of chapters and sections
% Uses titlesec. 

% If making compact version then put chapter start on same page
\ifbool{optioncompact}{\titleclass{\chapter}{straight}}{}  % possibilities are: straight, part, top, page

% Format the chapter and section heads
\titleformat{\chapter}[block]{\color{darki}\Large\scshape}{Chapter \thechapter}{1em}{}[\thispagestyle{firstpage}]
\titlespacing*{\chapter}{0em}{4ex}{2ex} 
\titleformat{\section}[block]{\color{darki}\large\scshape}{}{0em}{}[]
\titlespacing*{\section}{0em}{4ex}{1ex} 

% Here is the interaction with answers package.  
% Need to write the name of the chapter or section to the answer file.
% But that I can tell, I can't get \thetitle into titlesec's 
% \titleformat after-code.  So I write a new \chapter and \section
% that grab those, write the material to answers, and then run the command
% that titlesec has defined. 
%   Grab the name of the chapter, write it to the answers file, then
% invoke the titlesec \chapter command.
\let\chapterholder\chapter
\renewcommand{\chapter}{\@ifstar  % look out for \chapter*{Preface}
                     \jhchapterStar%
                     \jhchapterNoStar%
}
\newcommand{\jhchapterStar}[1]{\chapterholder{#1}}
\newcommand{\jhchapterNoStar}[1]{\ifbool{inappendix}{\relax}{\Writetofile{answers}{\protect\chapter{#1}}}\chapterholder{#1}}
% Same thing for the \section command
\let\sectionholder\section
\renewcommand{\section}{\@ifstar
                     \jhsectionStar%
                     \jhsectionNoStar%
}
\newcommand{\jhsectionStar}[1]{\sectionholder{#1}}
\newcommand{\jhsectionNoStar}[1]{\Writetofile{answers}{\protect\section{#1}}\sectionholder{#1}}
